package edu.gdkm.sql.dao;

import edu.gdkm.sql.pojo.GoodsAlbum;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsAlbumMapper {

    @Select("SELECT * FROM vueshop_goods_album")
    List<GoodsAlbum> findAll();

    @Select("SELECT * FROM vueshop_goods_album WHERE id = #{id}")
    @Results(id = "vueshopGoodsAlbumResultMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "goodsId", column = "goods_id"),
            @Result(property = "picture", column = "picture")
    })
    GoodsAlbum findById(@Param("id") Integer id);

    @Insert("INSERT INTO vueshop_goods_album(goods_id, picture) VALUES(#{goodsId}, #{picture})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(GoodsAlbum album);

    @Update("UPDATE vueshop_goods_album SET goods_id=#{goodsId}, picture=#{picture} WHERE id=#{id}")
    void update(GoodsAlbum album);

    @Delete("DELETE FROM vueshop_goods_album WHERE id=#{id}")
    void delete(@Param("id") Integer id);
    @Select("SELECT * FROM vueshop_goods_album WHERE goods_id = #{goodsId}")
    List<GoodsAlbum> findByGoodsId(@Param("goodsId") Integer goodsId);
}
